(require 'cl)
;; Speed up startup
(setq auto-mode-case-fold nil)

(when (version< emacs-version "25.1")
  (error "This requires Emacs 25.1 and above!"))

(when (not (version< emacs-version "29.0"))
  (setq package-native-compile nil))

;; Load path
;; Optimize: Force "lisp"" and "site-lisp" at the head to reduce the startup time.
(defun update-load-path (&rest _)
  "Update `load-path'."
  (dolist (dir '("site-lisp" "lisp"))
    (push (expand-file-name dir user-emacs-directory) load-path)))

(defun add-subdirs-to-load-path (&rest _)
  "Add subdirectories to `load-path'."
  (let ((default-directory (expand-file-name "site-lisp" user-emacs-directory)))
    (normal-top-level-add-subdirs-to-load-path)))

(advice-add #'package-initialize :after #'update-load-path)
(advice-add #'package-initialize :after #'add-subdirs-to-load-path)

;;在保存时自动清除行尾空格及文件结尾空行
(add-hook 'before-save-hook 'delete-trailing-whitespace)

(update-load-path)

;; Packages
;; Without this comment Emacs25 adds (package-initialize) here
(require 'init-package)

;; 测试启动速度 M-x benchmark-init/show-durations-tree 或者 M-x benchmark-init/show-durations-tabulated来查看启动的耗时细节
(use-package benchmark-init
  :ensure t
  :demand t
  :config
  ;; To disable collection of benchmark data after init is done.
  (add-hook 'after-init-hook 'benchmark-init/deactivate))

;;Core
(require 'init-basic)
(require 'init-completion)

(require 'init-evil)

(require 'init-tools)
(require 'init-writing)
(require 'init-reading)

;; UI
(require 'init-ui)
(require 'init-window)
(require 'init-better-defaults)

;;Tools
(require 'init-org)
(require 'init-git)
(require 'init-ctags)
(require 'init-syntaxcheck)
(require 'init-snippets)
(require 'init-lsp)

;; Frameworks
;; yaml init , shell etc
;; init-prog.el
(require 'init-web)
(require 'init-gpu)
(require 'init-persp)

;;language
(require 'init-lisp)
(require 'init-javascript)
(require 'init-python)
(require 'init-c)
(require 'init-dart)
(require 'init-lua)

;;personal
(require 'init-keybindings)
(require 'kind-all-the-icons)
(put 'dired-find-alternate-file 'disabled nil)
